#!/usr/bin/env python
# -*- coding: utf-8 -*-
#

import logging

#### ---- test root logger ---- ####

def test_one(tag) :
    logger = logging.getLogger()
    logger.info('==== testing Category:Root begin ====')
    logger.error('<%s> ERROR Logging Messsage.', tag)
    logger.warn('<%s> WARN Logging Messsage.', tag)
    logger.info('<%s> INFO Logging Messsage.', tag)
    logger.debug('<%s> DEBUG Logging Messsage.', tag)
    logger.trace('<%s> TRACE Logging Messsage.', tag)
    logger.info('==== testing Category:Root   end ====')

    logger = logging.getLogger('CHORD')
    logger.info('==== testing Category:CHORD begin ====')
    logger.error('<%s> ERROR Logging Messsage.', tag)
    logger.warn('<%s> WARN Logging Messsage.', tag)
    logger.info('<%s> INFO Logging Messsage.', tag)
    logger.debug('<%s> DEBUG Logging Messsage.', tag)
    logger.trace('<%s> TRACE Logging Messsage.', tag)
    logger.info('==== testing Category:CHORD   end ====')

test_one('test-00')

configure = '''
logging.rootLogger = DEBUG, A1, A2
logging.appender.A1 = ConsoleAppender
logging.appender.A1.layout = SimpleLayout
logging.appender.A2 = FileAppender
logging.appender.A2.file = /tmp/test-chord.log
logging.appender.A2.layout = SimpleLayout
'''
logging.configure( configure )

test_one('test-01')

configure += '''
logging.logger.CHORD = TRACE, A2
'''
logging.configure( configure )

test_one('test-02')

configure = '''
logging.rootLogger = DEBUG, A2
logging.appender.A2 = FileAppender
logging.appender.A2.file = /tmp/test-chord.log
logging.appender.A2.rolling = daily
logging.appender.A2.layout = SimpleLayout
'''
logging.configure( configure )

test_one('test-03')

configure = '''
logging.rootLogger = DEBUG, A2
logging.appender.A2 = FileAppender
logging.appender.A2.file = /tmp/test-chord.log
logging.appender.A2.rolling = hourly
logging.appender.A2.layout = SimpleLayout
'''
logging.configure( configure )

test_one('test-04')

# test for pattern layout
configure = '''
logging.rootLogger = DEBUG, A2
logging.appender.A2 = FileAppender
logging.appender.A2.file = /tmp/test-chord.log
logging.appender.A2.rolling = hourly
logging.appender.A2.layout = PatternLayout
logging.appender.A2.layout.ConversionPattern = %t [MODULE=%M] [LEVEL=%p] [HOST=%h] [PID=%P] %m
'''
logging.configure( configure )

test_one('test-05')

# test for filter
configure = '''
logging.rootLogger = DEBUG, A2
logging.appender.A2 = FileAppender
logging.appender.A2.file = /tmp/test-chord.log
logging.appender.A2.rolling = hourly
logging.appender.A2.layout = SimpleLayout
logging.appender.A2.filter.1 = LevelMatchFilter
logging.appender.A2.filter.1.LevelToMatch = ERROR, INFO
logging.appender.A2.filter.1.AcceptOnMatch = true
'''
logging.configure( configure )

test_one('test-06')

